<template>
	<view id="echart-container">
		<view class="tips">
			<view class="item">
				<text class="dot" style="background-color: #E62029;"></text>
				<text>总工程数：{{all}}</text>
			</view>
			<view class="item">
				<text class="dot" style="background-color: #D57FF8;"></text>
				<text>施工中数：{{wip}}</text>
			</view>
			<view class="item">
				<text class="dot" style="background-color: #FFC107;"></text>
				<text>完工数：{{ip}}</text>
			</view>
		</view>
		<view class="charts-box">
			<qiun-data-charts type="column" :chartData="chartData" />
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			all: Number,
			wip: Number,
			ip: Number,
			nodeList: Array
		},
		beforeUpdate() {
			console.log(this.nodeList)
			this.getData()
		},
		name: "owner-echart",
		methods: {
			getData() {
				console.log(this.nodeList)
				if (this.nodeList.length != 0) {
					let x = []
					let number = []
					for (let i = 0; i < this.nodeList.length; i++) {
						x.push(this.nodeList[i].progressValue + '%')
						let element = {
							"value": this.nodeList[i].count
						}
						if (this.nodeList[i].progressValue == 100) {
							element.color = "#FFC107"
						} else {
							element.color = "#D57FF8"
						}
						number.push(element)
					}
					let data = {
						"categories": x,
						"series": [{
							"name": "数量",
							"data": number,
						}]
					}
					this.chartData = data
				}
			}
		},
		data() {
			return {
				chartData: {}
			};
		}
	}
</script>

<style lang="scss" scoped>
	#echart-container {
		background-color: #FFFFFF;
		height: 460rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		border-radius: 20rpx;
		border: 1rpx solid #efefef;

		.tips {
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			align-content: space-around;
			color: #333333;
			font-size: 24rpx;

			.item {
				margin-right: 20rpx;

				// display: inline-flex;
				.dot {
					display: block;
					width: 20rpx;
					height: 20rpx;
					border-radius: 50%;
					border: 1rpx solid #efefef;
					margin-right: 15rpx;
				}

				text-align: center;
				line-height: 20rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
			}
		}

		/* 请根据需求修改图表容器尺寸，如果父容器没有高度图表则会显示异常 */
		.charts-box {
			margin-top: 40rpx;
			width: 100%;
			height: 300rpx;
		}
	}
</style>
